import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:ft_reader/common/utils/screen.dart';
import 'package:ft_reader/pages/home_page.dart';

import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux/redux.dart';

import 'common/global_state.dart';
// import 'common/utils/settings.dart';


void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // final value = await AppSetting.instance.getAppColor();
  final value = null;
  print("value = ${value}");

  Store<GlobalState> store = new Store<GlobalState>(appReducer,
    initialState: new GlobalState(
      themeData: ThemeData(
        primaryColor: (value == null || value == 0)
            ? Colors.deepPurpleAccent
            : Color(value)
      )
    ));

  runApp(MyApp(
    store: store
  ));
  Screen.init();
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
}

class MyApp extends StatelessWidget {
  final Store<GlobalState> store;
  const MyApp({Key key, this.store}): super(key: key);
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return StoreProvider(
      store: store,
      child: StoreBuilder<GlobalState>(
        builder: (context, state) {
          return MaterialApp(
            title: 'Flutter Reader',
            theme: store.state.themeData,
            home: HomePage(),
            routes: <String, WidgetBuilder>{},
          );
        },
      ),
    );
  }

}
